package com.kye.express.business.home.productintroduction;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

import com.jakewharton.rxbinding2.view.RxView;
import com.kye.base.DebounceObservableTransformer;
import com.kye.express.R;
import com.kye.express.business.base.BaseToolbarActivity;
import com.kye.express.business.web.KyeWebActivity;
import com.kye.express.config.KyeResAction;
import com.kye.express.databinding.ActivityProductIntroductionBinding;

import io.reactivex.functions.Consumer;

/**
 * 产品介绍
 */
public class ProductIntroductionActivity extends BaseToolbarActivity {
    private ActivityProductIntroductionBinding mBinding;
    private Context mContext;

    public static void startActivity(Context context) {
        Intent intent = new Intent(context, ProductIntroductionActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_product_introduction);
        mContext = this;
        setUpToolbar((Toolbar) findViewById(R.id.toolbar));
        setTitle(getString(R.string.prod_introduction));
        initEvent();
    }

    private void initEvent() {
        RxView.clicks(mBinding.rlTodayArrive)
                .compose(new DebounceObservableTransformer<>())
                .compose(this.bindToLifecycleDestroy())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        KyeWebActivity.startActivity(mContext, KyeResAction.ToDayArriveKey, getString(R.string.prod_today_arrive), false);
                    }
                });
        RxView.clicks(mBinding.rlNextdayArrive)
                .compose(new DebounceObservableTransformer<>())
                .compose(this.bindToLifecycleDestroy())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        KyeWebActivity.startActivity(mContext, KyeResAction.NextDayArriveKey, getString(R.string.prod_nexday_arrive), false);
                    }
                });
        RxView.clicks(mBinding.rlOtherdayArrive)
                .compose(new DebounceObservableTransformer<>())
                .compose(this.bindToLifecycleDestroy())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        KyeWebActivity.startActivity(mContext, KyeResAction.OtherDayArriveKey, getString(R.string.prod_otherday_arrive), false);
                    }
                });
        RxView.clicks(mBinding.rlLand)
                .compose(new DebounceObservableTransformer<>())
                .compose(this.bindToLifecycleDestroy())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        KyeWebActivity.startActivity(mContext, KyeResAction.LandArriveKey, getString(R.string.prod_land_carry), false);
                    }
                });
        RxView.clicks(mBinding.rlSamecity)
                .compose(new DebounceObservableTransformer<>())
                .compose(this.bindToLifecycleDestroy())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        KyeWebActivity.startActivity(mContext, KyeResAction.LocalArriveKey, getString(R.string.prod_samecity), false);
                    }
                });
        RxView.clicks(mBinding.rlAddService)
                .compose(new DebounceObservableTransformer<>())
                .compose(this.bindToLifecycleDestroy())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        IncrementServiceActivity.startActivity(mContext);
                    }
                });
    }
}
